package com.example.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.example.network.Response;
import com.example.resource.Project;

public class ProjectResponse extends Response {

	public List<Project> projectList;

	@Override
	protected void jsonToObject() {
		projectList = new ArrayList<Project>();
		try {
			JSONObject data = reposonJson.getJSONObject("result");
			JSONArray array = data.getJSONArray("infos");
			int size = array.length();
			for (int i = 0; i < size; i++) {
				JSONObject object = array.getJSONObject(i);
				Project project = new Project();
				project.tradeId = object.optInt("tradeId");
				project.demandId = object.optInt("demandId");
				project.deadline = object.optString("deadline");
				project.effectiveDate = object.optString("effectiveDate");
				project.guaranteeName = object.optString("guaranteeName");
				project.investCompleteTime = object.optString("investCompleteTime");
				project.tradeName = object.optString("tradeName");
				project.tradeStatus = object.optInt("tradeStatus");
				project.tradeAmount = object.optString("tradeAmount");
				project.tradeLoanedAmount = object.optString("tradeLoanedAmount");
				project.tradeAnnualRate = object.optString("tradeAnnualRate");
				project.timePeriod = object.optString("timePeriod");
				project.investStartTime = object.optString("investStartTime");
				project.persontage = object.optString("persontage");
				project.requiredAmount = object.optLong("requiredAmount");
				projectList.add(project);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

}